package com.yuexiao.entity;

import lombok.Data;

import java.util.Map;

/**
 * @ClassName:ResultInfo
 * @Auther: YUEXIAO
 * @Description: 返回信息实体类
 * @Date: 2022/8/10 20:01
 * @Version: v1.0
 */
@Data
public class ResultInfo<T> {
    private Integer code; //编码: 1 成功, 0 失败
    private String msg; //错误信息
    private T data; //返回数据
    private Map<String, Object> extend; //扩展数据

    public static <T> ResultInfo<T> success(T data) {
        ResultInfo<T> resultInfo = new ResultInfo<>();
        resultInfo.setCode(1);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static <T> ResultInfo<T> error(String msg) {
        ResultInfo<T> resultInfo = new ResultInfo<>();
        resultInfo.setCode(0);
        resultInfo.setMsg(msg);
        return resultInfo;
    }

   public ResultInfo<T> add(String key, Object value) {
        this.getExtend().put(key, value);
        return this;
    }

}
